home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / MotifInternalFrameBorder.java < prev    next >
Text File  |  1998-06-30  |  6KB  |  175 lines

  1. /*
  2.  * @(#)MotifInternalFrameBorder.java    1.17 98/02/02
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20. package com.sun.java.swing.plaf.motif;
  21.  
  22. import java.awt.Graphics;
  23. import java.awt.Dimension;
  24. import java.awt.Rectangle;
  25. import java.awt.Color;
  26. import java.awt.Insets;
  27.  
  28. import java.awt.*;
  29. import java.beans.*;
  30.  
  31. import com.sun.java.swing.*;
  32. import com.sun.java.swing.border.AbstractBorder;
  33.  
  34. /**
  35.  * <p>
  36.  * Warning: serialized objects of this class will not be compatible with
  37.  * future swing releases.  The current serialization support is appropriate
  38.  * for short term storage or RMI between Swing1.0 applications.  It will
  39.  * not be possible to load serialized Swing1.0 objects with future releases
  40.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  41.  * baseline for the serialized form of Swing objects.
  42.  *
  43.  * @version 1.17 02/02/98
  44.  * @author unknown
  45.  */
  46. public class MotifInternalFrameBorder extends MotifFrameBorder {
  47.  
  48.     JInternalFrame frame;
  49.  
  50.     // The size of the bounding box for Motif frame corners.
  51.     public final static int CORNER_SIZE = 24;
  52.  
  53.     /** Constructs an InternalFrameBorder for the InternalFrame
  54.       * <b>aFrame</b>.
  55.       */
  56.     public MotifInternalFrameBorder(JInternalFrame aFrame) {
  57.         super(aFrame);
  58.         frame = aFrame;
  59.     }
  60.  
  61.     /** Sets the InternalFrameBorder's InternalFrame.
  62.       */
  63.     public void setFrame(JInternalFrame aFrame) {
  64.         frame = aFrame;
  65.     }
  66.  
  67.     /** Returns the InternalFrameBorder's InternalFrame.
  68.       * @see #setFrame
  69.       */
  70.     public JInternalFrame frame() {
  71.         return frame;
  72.     }
  73.  
  74.     /** Returns the width of the InternalFrameBorder's resize controls,
  75.       * appearing along the InternalFrameBorder's bottom border.  Clicking
  76.       * and dragging within these controls lets the user change both the
  77.       * InternalFrame's width and height, while dragging between the controls
  78.       * constrains resizing to just the vertical dimension.  Override this
  79.       * method if you implement your own bottom border painting and use a
  80.       * resize control with a different size.
  81.       */
  82.     public int resizePartWidth() {
  83.         if (!frame.isResizable()) {
  84.             return 0;
  85.         }
  86.         return MotifFrameBorder.BORDER_SIZE;
  87.     }
  88.  
  89.     /** Draws the InternalFrameBorder's top border.
  90.      */
  91.     protected boolean drawTopBorder(Component c, Graphics g, 
  92.                                     int x, int y, int width, int height) {
  93.         if (super.drawTopBorder(c, g, x, y, width, height) && 
  94.             frame.isResizable()) {
  95.             g.setColor(getFrameShadow());
  96.             g.drawLine(CORNER_SIZE - 1, y + 1, CORNER_SIZE - 1, y + 4);
  97.             g.drawLine(width - CORNER_SIZE - 1, y + 1, 
  98.                        width - CORNER_SIZE - 1, y + 4);
  99.  
  100.             g.setColor(getFrameHighlight());
  101.             g.drawLine(CORNER_SIZE, y, CORNER_SIZE, y + 4);
  102.             g.drawLine(width - CORNER_SIZE, y, width - CORNER_SIZE, y + 4);
  103.             return true;
  104.         }
  105.         return false;
  106.     }
  107.  
  108.     /** Draws the InternalFrameBorder's left border.
  109.       */
  110.     protected boolean drawLeftBorder(Component c, Graphics g, int x, int y, 
  111.                                      int width, int height) {
  112.         if (super.drawLeftBorder(c, g, x, y, width, height) && 
  113.             frame.isResizable()) {
  114.             g.setColor(getFrameHighlight());
  115.             int topY = y + CORNER_SIZE;
  116.             g.drawLine(x, topY, x + 4, topY);
  117.             int bottomY = height - CORNER_SIZE;
  118.             g.drawLine(x + 1, bottomY, x + 5, bottomY);
  119.             g.setColor(getFrameShadow());
  120.             g.drawLine(x + 1, topY - 1, x + 5, topY - 1);
  121.             g.drawLine(x + 1, bottomY - 1, x + 5, bottomY - 1);
  122.             return true;
  123.         }
  124.         return false;
  125.     }
  126.  
  127.     /** Draws the InternalFrameBorder's right border.
  128.       */
  129.     protected boolean drawRightBorder(Component c, Graphics g, int x, int y, 
  130.                                       int width, int height) {
  131.         if (super.drawRightBorder(c, g, x, y, width, height) && 
  132.             frame.isResizable()) {
  133.             int startX = width - getBorderInsets(c).right;
  134.             g.setColor(getFrameHighlight());
  135.             int topY = y + CORNER_SIZE;
  136.             g.drawLine(startX, topY, width - 2, topY);
  137.             int bottomY = height - CORNER_SIZE;
  138.             g.drawLine(startX + 1, bottomY, startX + 3, bottomY);
  139.             g.setColor(getFrameShadow());
  140.             g.drawLine(startX + 1, topY - 1, width - 2, topY - 1);
  141.             g.drawLine(startX + 1, bottomY - 1, startX + 3, bottomY - 1);
  142.             return true;
  143.         }
  144.         return false;
  145.     }
  146.  
  147.     /** Draws the InternalFrameBorder's bottom border.
  148.       */
  149.     protected boolean drawBottomBorder(Component c, Graphics g, int x, int y, 
  150.                                        int width, int height) {
  151.         if (super.drawBottomBorder(c, g, x, y, width, height) &&
  152.             frame.isResizable()) {
  153.             int startY = height - getBorderInsets(c).bottom;
  154.  
  155.             g.setColor(getFrameShadow());
  156.             g.drawLine(CORNER_SIZE - 1, startY + 1, 
  157.                        CORNER_SIZE - 1, height - 1);
  158.             g.drawLine(width - CORNER_SIZE, startY + 1, 
  159.                        width - CORNER_SIZE, height - 1);
  160.         
  161.             g.setColor(getFrameHighlight());
  162.             g.drawLine(CORNER_SIZE, startY, CORNER_SIZE, height - 2);
  163.             g.drawLine(width - CORNER_SIZE + 1, startY, 
  164.                        width - CORNER_SIZE + 1, height - 2);
  165.             return true;
  166.         }
  167.         return false;
  168.     }
  169.  
  170.     // Returns true if the associated internal frame has focus.
  171.     protected boolean isActiveFrame() {
  172.         return frame.isSelected();
  173.     }
  174. }
  175.